package chapter08.mapreduce.partition;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Partitioner;

public class ProvincePartitioner extends Partitioner<Text, FlowBean> {
    @Override
    public int getPartition(Text text, FlowBean flowBean, int i) {
        // 1 获取电话号码的前三位
        String preNum = text.toString().substring(0, 3);

        int partition = 4;

        // 2 判断是哪个省
        switch (preNum) {
            case "136":
                partition = 0;
                break;

            case "137":
                partition = 1;
                break;

            case "138":
                partition = 2;
                break;

            case "139":
                partition = 3;
                break;

            default:
                break;
        }

        return partition;
    }
}
